# load packages

pacman::p_load(tidyverse, tmap, sf, rnaturalearth)

### figure A.1 (public pools in germany) ----

# load german state shape file
germany <- ne_states(country = "Germany", returnclass = "sf")

# load pool location data
pools <- read_rds('data/pool_locations.rds') 

# increase space around map to make space for legend
bbox <- st_bbox(germany) 
xrange <- bbox$xmax - bbox$xmin 
yrange <- bbox$ymax - bbox$ymin 
bbox[3] <- bbox[3] + (0.15 * xrange) 

bbox <- bbox %>% 
    st_as_sfc()

# create map
pool_map <- tm_shape(germany, bbox = bbox) +
    tm_borders(lwd = 1) +
    tm_shape(pools) +
    tm_dots(size = 0.05, palette = c("#d7191c", "#0000FF"), col = "Pool Type", 
            alpha = 0.7) +
    tm_legend(show = T, frame = T, bg.color = "white", bg.alpha = 0.9, 
              frame.lwd = .5, legend.position = c(.7,.29), legend.outside = F) +
    tm_layout(frame = F, legend.text.size = 1)

pool_map

# clean
rm(list = ls())